import 'package:get/get.dart';
import 'package:laos_mall/app_route.dart';
import 'package:laos_mall/common/base/base_controller.dart';
import 'package:laos_mall/common/utils/http_util.dart';
import 'package:laos_mall/models/user/user_model.dart';
import 'package:laos_mall/pages/accout/address/view.dart';
import 'package:laos_mall/pages/accout/balance/view.dart';
import 'package:laos_mall/pages/accout/coupon/view.dart';
import 'package:laos_mall/pages/accout/message/view.dart';
import 'package:laos_mall/pages/accout/user_info/view.dart';
import 'package:laos_mall/pages/main/logic.dart';
import 'package:laos_mall/pages/order/view.dart';
import 'package:laos_mall/pages/point_mall/view.dart';

class MyLogic extends BaseController {
  UserModel? userModel;
  UserInfoModel? infoModel;
  var isMember = false.obs;
  final orderTitles = ["in_store_order",'online_order','scale_order'];
  final walletTitles = ["points_shop",'account_manager','shipping_address',"shopping_cart","message_inbox","help_center"];

  @override
  Future<void> Function()? get request => ()async{
    requestUserDetail();
    var infoReq = await HttpUtil.restApi.userInfo({});
    infoModel = infoReq.data?.item;
    update();
  };

  requestUserDetail()async{
    var req = await HttpUtil.restApi.userDetail({});
    userModel = req.data?.item;
  }

  showQRCode(){
    Get.toNamed(AppRouter.memberQrCode);
  }

  jumpSetting(){
    Get.toNamed(AppRouter.setting);
  }

  jumpUserInfo(){
    Get.to(()=>UserInfoPage());
  }

  jumpOrder(int index){
    Get.to(()=>OrderPage(),arguments: index + 1);
  }

  jumpBalance(){
    Get.to(()=> BalancePage());
  }

  jumpCoupon()=> Get.to(()=> CouponPage());

  jumpPoint()=> Get.to(()=> PointMallPage());

  clickOrder(int index){
    switch(index){
      case 0:
        jumpPoint();
        break;
      case 2:
        Get.to(()=> AddressPage());
        break;
      case 3:
        final logic = Get.find<MainLogic>();
        logic.index.value = 3;
      case 4:
        Get.to(()=> MessagePage());
        break;
      case 5:
        Get.to(()=> MessagePage(),arguments: {"is_help":true});
        break;
    }
  }
}
